package  nid.utils
{
	import flash.display.BitmapData;
	import flash.geom.Rectangle;
	/**
	 * ...
	 * @author Nidin P Vinayakan
	 */
	public class BitmapUtils 
	{
		
		public function BitmapUtils() 
		{
			
		}
		public static function GetPart(src_bmp_data:BitmapData, param2:int, param3:int, param4:int, param5:int) : BitmapData
        {
            var bmp_data:BitmapData = new BitmapData(param4, param5);
            bmp_data.copyPixels(src_bmp_data, new Rectangle(param2, param3, param4, param5), src_bmp_data.rect.topLeft);
            return bmp_data;
        }
		
		public static function Desaturate(bmp_data:BitmapData) : BitmapData
        {
            var RGBpixel:uint = 0;
            var r:int = 0;
            var g:int = 0;
            var b:int = 0;
            var j:int = 0;
            var i:int = 0;
            while (i < bmp_data.width)
            {
                
                j = 0;
                while (j < bmp_data.height)
                {
                    
                    RGBpixel = bmp_data.getPixel(i, j);
                    r = RGBpixel >> 16 & 0xff;
                    g = RGBpixel >> 8 & 0xff;
                    b = RGBpixel & 0xff;
                    var gray:int = 0.299 * r + 0.587 * g + 0.114 * b;
                    b = 0.299 * r + 0.587 * g + 0.114 * b;
                    g = gray;
                    r = gray;
                    bmp_data.setPixel(i, j, r << 16 | g << 8 | b);
                    j++;
                }
                i++;
            }
            return bmp_data;
        }
	}

}